<%@page import="java.text.DecimalFormat"%>
<%@page import="java.util.ArrayList"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@page import="com.burger.counter.beans.ShoppingCart"%>
<%@page import="com.burger.counter.beans.Item"%>
<%
	Double subTotal = 0.0;
	DecimalFormat df = new DecimalFormat("##.##");
	ShoppingCart cart;
	ArrayList<Item> itemList;
	Item item;
	Double tax=0.0;
	tax=(Double)session.getAttribute("Tax");
	System.out.println("Calling view order");
	%>
<%
	cart = (ShoppingCart) session.getAttribute("Cart");

	
%>
<script type="text/javascript">
function show_alert()
{
alert("Empty the cart?");
}
</script>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>ViewOrder</title>
</head>
<body>
	<link rel="stylesheet" href="default.css" type="text/css"></link>
	<%@ include file="header.jsp"%>
	<form name="ViewOrder" method="post" action="HandleOrderServlet">
		<div class="inputColumn" id="viewOrder"
			style="text-align: center; border: thin; margin: auto;">
			<table border="1">
				<tr>
					<td align="right" colspan="3"><input type="button"
						value="Refresh Cart" onClick="window.location.reload()"></td>
				</tr>
				<%
				if(cart!=null)
				{
					int i;
					itemList=(ArrayList<Item>) cart.getItemInCart();	
					if(itemList.size()==0)
					{
						
						%>
				<tr>
					<td align="right" colspan="2">Empty Cart</td>
				</tr>


				<%
							}
						
					else
					{
					for (i = 0; i < itemList.size(); i++) {
						item=itemList.get(i);
						subTotal+=item.getItemPrice();
						
				%>
				<tr bordercolor="red" style="border-style: none" bordercolor="white">
				<td>
				<input type="radio"
						value='<%=item.getItemId()%>'
						name="ItemId" /></td>
					<td bordercolor="red" bordercolor="white"><label
						name="ItemName" style="size: 30;"><%=item.getItemName()%></label>
					</td>
					<td bordercolor="red" bordercolor="white"><label
						name="ItemPrice" style="size: 30;"><%=item.getItemPrice()%></label>
					</td>
					

				</tr>
				<tr>

				</tr>



				<%
					}
				%>	
					<tr>
					<td align="right" colspan="3">
					<INPUT TYPE="submit" VALUE="Remove From Cart" name="SUBMIT"></td>
					</td>
				</tr>
				<tr>
					<td align="right" colspan="3"><label name="SubTotal" style="size: 30;">SubTotal<%=df.format(subTotal)%></label>
					</td>
				</tr>
				<tr>
					<td align="right" colspan="3"><label name="Tax" style="size: 30;">Tax<%=tax%></label>
					</td>
				</tr>
				<tr>
					<td align="right" colspan="3"><label name="Total" style="size: 30;">Total<%=tax + subTotal%></label>
					</td>
				</tr>
				<tr>
					<td align="right" colspan="3">
					
					<INPUT TYPE="submit"
						VALUE="CheckOut" name="SUBMIT">
						<INPUT TYPE="submit"
						VALUE="Cancel Order" onclick="show_alert()" name="SUBMIT">
						</td>
				</tr>
				<%
				session.setAttribute("SubTotal" ,subTotal);
					session.setAttribute("Total",tax+subTotal);
					}
				
				%>
				
				<%
					
				}
				else
				{
				%>
				<tr>
					<td align="right" colspan="2">Empty Cart</td>
				</tr>


				<%
					}
				
				%>
			</table>


		</div>
	</form>
</body>
</html>